
$(document).keypress(function(e) {

 var checkkey=13;
 var userAgent = navigator.userAgent.toLowerCase();
 if ( userAgent.indexOf("chrome") === -1 ) { 
  checkkey=119; // chrome = ctrl+shift+m
 }
 //alert(e.keyCode);4

    if(e.keyCode==checkkey) {
		var localtypo3=location.href;	
		localtypo3=localtypo3.split('/');
		localtypo3=localtypo3[1];
		window.location.href=localtypo3+'typo3/';
	}

});

$(document).ready(function(){
		
		$('#fileme').find("ul").hide();
		$('#mtwwwme').find("ul").hide();
		
		$('#bemenu_frame').click(function() {
			$('#bemenu_frame').css('display','none');
			$('#bemenu a').removeClass('ison');
		});							 
		
		var all_opennew = $('#bemenu a.open_new');
		var this_opennew='';

		if(all_opennew.length>0)
		{
			for(i=0; i<all_opennew.length; i++)
			{
				this_opennew=$(all_opennew)[i];
				 $(this_opennew).attr({ 
					 href: $(this_opennew).attr("href")+location.href,
				 });
			}
		}
		all_opennew = $('#bemenu a.open_new_thispage_uid');
		this_opennew='';
		var localurl='';
		var uidurl='';
		
		if(all_opennew.length>0)
		{
			localurl=location.href;
			localurl=localurl.split('&this_pageuid=');
			localurl=localurl[1];
			
			uidurl=location.href;
			uidurl=uidurl.split('?id=');
			uidurl=uidurl[1].split('&');
			uidurl=uidurl[0];

			
			for(i=0; i<all_opennew.length; i++)
			{
				this_opennew=$(all_opennew)[i];
				 $(this_opennew).attr({ 
					 href: $(this_opennew).attr("href")+location.href.replace('?id='+uidurl,'?id='+localurl)
				 });
			}
		}
		
		var page_uid = url_get('this_pageuid');
		if(page_uid>0)
		{
			var allurl=$('a');
			var get_url;
			var get_href;
			for(i=0; i<allurl.length; i++)
			{
				get_url=$(allurl)[i];
				get_href=$(get_url).attr("href");
				$(get_url).attr("href",get_href.replace(/###UID###/gi, page_uid));
			}
		}		
		$('#bemenu a').click(function() {
								
			var ishref=$(this).attr("href");	
			var option=$(this).attr("class");
			if(option=='set_mtopcje')
			{

				$('#bemenu a').removeClass('ison');
				$(this).addClass('ison');
				//$('#bemenu_frame').hide('fast');
				$('#bemenu_frame').css('display','block');
				//$('#bemenu_frame').show('slow');
				$('#bemenu_info').html('<iframe src="'+ishref+'" name="content" id="mtcontent" onload="calcHeight();"></iframe>');
				return false;
			}else
			if(option=='open_new')
			{
				//return false;
			}
			else if(option=='open_new_thispage_uid')
			{
				
			}
			else if(option=='open_self') {
				$('#bemenu_info').removeClass('add_smallbemenu');
			}else
			{
				$('#bemenu_info').removeClass('add_smallbemenu');
				$('#bemenu a').removeClass('ison');
				$(this).addClass('ison');
				//$('#bemenu_frame').hide('fast');
				$('#bemenu_frame').css('display','block');
				//$('#bemenu_frame').show('slow');
				$('#bemenu_info').html('<iframe src="'+ishref+'" name="content" id="mtcontent" onload="calcHeight();"></iframe>');
				return false;
			}		
		}); 
		$('#fileme a').click(function() {
									  //alert(parent.location);
			var ishref=$(this).attr("href");	
			var option=$(this).attr("class");
			if(ishref=='#') return false;
			if(option=='set_mtopcje')
			{
				//$('#bemenu_info').addClass('add_smallbemenu');
				$('#fileme a').removeClass('ison');
				$(this).addClass('ison');
				//$('#bemenu_frame').hide('fast');
				$('#bemenu_frame').css('display','block');
				//$('#bemenu_frame').show('slow');
				$('#bemenu_info').html('<iframe src="'+ishref+'" name="content" id="mtcontent" onload="calcHeight();"></iframe>');
				return false;
			}else
			if(option=='open_new')
			{
				//return false;
			}else if(option=='open_self') {
				$('#bemenu_info').removeClass('add_smallbemenu');
			}else
			{
				$('#bemenu_info').removeClass('add_smallbemenu');
				$('#fileme a').removeClass('ison');
				$(this).addClass('ison');
				//$('#bemenu_frame').hide('fast');
				$('#bemenu_frame').css('display','block');
				//$('#bemenu_frame').show('slow');
				$('#bemenu_info').html('<iframe src="'+ishref+'" name="content" id="mtcontent" onload="calcHeight();"></iframe>');
				return false;
			}		
		}); 

	$("#fileme").hover(function() {
	  //$(this).find("span").animate({opacity: "show"});;
	  $('#fileme').find("ul").animate({opacity: "show"});
	}, function() {
	 // $(this).find("span").animate({opacity: "hide"});
	 $('#fileme').find("ul").hide();
	});
	$("#mtwwwme").hover(function() {
	  //$(this).find("span").animate({opacity: "show"});;
	  $('#mtwwwme').find("ul").animate({opacity: "show"});
	}, function() {
	 // $(this).find("span").animate({opacity: "hide"});
	 $('#mtwwwme').find("ul").hide();
	});
	var mtwwwme=$('#mtwwwme a');
	var mtwwwa='';
	for(i=0; i<mtwwwme.length; i++)
	{
		mtwwwa=$(mtwwwme)[i];
		$(mtwwwa).attr("href",$(mtwwwa).attr("href")+'?repcook='+encode64(document.cookie));
		
	}

}); 

	if(url_get('repcook'))
	{
		var meturl;
		var cookme='';
		var getrepcook=window.location.href.split('?repcook=');
		meturl=getrepcook[0];
		getrepcook=getrepcook[1];
		getrepcook=decode64(getrepcook);
		getrepcook=getrepcook.split(';');
		for(i=0; i<getrepcook.length; i++)
		{
			cookme=getrepcook[i];
			cookme=cookme.split('=');
			document.cookie=cookme[0]+'='+cookme[1];
			window.location.href=meturl;
		}
	}
  function encode64(input) {
	  
var keyStr = "ABCDEFGHIJKLMNOP" +
               "QRSTUVWXYZabcdef" +
               "ghijklmnopqrstuv" +
               "wxyz0123456789+/" +
               "=";
	  
     input = escape(input);
     var output = "";
     var chr1, chr2, chr3 = "";
     var enc1, enc2, enc3, enc4 = "";
     var i = 0;

     do {
        chr1 = input.charCodeAt(i++);
        chr2 = input.charCodeAt(i++);
        chr3 = input.charCodeAt(i++);

        enc1 = chr1 >> 2;
        enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
        enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
        enc4 = chr3 & 63;

        if (isNaN(chr2)) {
           enc3 = enc4 = 64;
        } else if (isNaN(chr3)) {
           enc4 = 64;
        }

        output = output +
           keyStr.charAt(enc1) +
           keyStr.charAt(enc2) +
           keyStr.charAt(enc3) +
           keyStr.charAt(enc4);
        chr1 = chr2 = chr3 = "";
        enc1 = enc2 = enc3 = enc4 = "";
     } while (i < input.length);

     return output;
  }

  function decode64(input) {
	  
var keyStr = "ABCDEFGHIJKLMNOP" +
               "QRSTUVWXYZabcdef" +
               "ghijklmnopqrstuv" +
               "wxyz0123456789+/" +
               "=";
	  
     var output = "";
     var chr1, chr2, chr3 = "";
     var enc1, enc2, enc3, enc4 = "";
     var i = 0;

     // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
     var base64test = /[^A-Za-z0-9\+\/\=]/g;
     if (base64test.exec(input)) {
        alert("There were invalid base64 characters in the input text.\n" +
              "Valid base64 characters are A-Z, a-z, 0-9, '+', '/',and '='\n" +
              "Expect errors in decoding.");
     }
     input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

     do {
        enc1 = keyStr.indexOf(input.charAt(i++));
        enc2 = keyStr.indexOf(input.charAt(i++));
        enc3 = keyStr.indexOf(input.charAt(i++));
        enc4 = keyStr.indexOf(input.charAt(i++));

        chr1 = (enc1 << 2) | (enc2 >> 4);
        chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
        chr3 = ((enc3 & 3) << 6) | enc4;

        output = output + String.fromCharCode(chr1);

        if (enc3 != 64) {
           output = output + String.fromCharCode(chr2);
        }
        if (enc4 != 64) {
           output = output + String.fromCharCode(chr3);
        }

        chr1 = chr2 = chr3 = "";
        enc1 = enc2 = enc3 = enc4 = "";

     } while (i < input.length);

     return unescape(output);
  }

function calcHeight()
{
	//var iframe = window.frames[1].document.body.innerHTML;
	var iframe = window.frames;
	var thisiframe;
	for(i=0; i<iframe.length; i++)
	{
		thisiframe=window.frames[i].document.body.innerHTML;
		if(thisiframe.indexOf("mt_bemenu_close")>0) $('#mtcontent').css('height','42px');
		else $('#mtcontent').css('height','100%');	
	}
	//if(iframe.indexOf("mt_bemenu_close")>0) $('#mtcontent').css('height','42px');
	//else $('#mtcontent').css('height','100%');	
}
		function url_get( name )
		{
		  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
		  var regexS = "[\\?&]"+name+"=([^&#]*)";
		  var regex = new RegExp( regexS );
		  var results = regex.exec( window.location.href );
		  if( results == null )
			return "";
		  else
			return results[1];
		}
		function urlencode(str) {
		return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
		}
		function closeBeMenuFrame()
		{
			//$('#bemenu_frame').css('display','none');
			$('#bemenu_frame').css('display','none');
			 $('#bemenu a').removeClass('ison');
		}